package org.ling.xuan.table;

import org.ling.xuan.entity.mo.SvnCommitCheck;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class SvnCommitCheckTableModel extends AbstractTableModel {
    private final List<SvnCommitCheck> svnCommitChecks;
    private final String[] columnNames = {"fileName", "filePath", "svnStatus", "checkMsg"};

    public SvnCommitCheckTableModel(List<SvnCommitCheck> svnCommitChecks) {
        this.svnCommitChecks = svnCommitChecks;
    }

    @Override
    public int getRowCount() {
        return svnCommitChecks.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        SvnCommitCheck localAdd = svnCommitChecks.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return localAdd.getFileName();
            case 1:
                return localAdd.getFilePath();
            case 2:
                return localAdd.getModifyStatus();
            case 3:
                return localAdd.getMsg();
            default:
                return null;
        }
    }

    public void removeRow(int rowIndex) {
        svnCommitChecks.remove(rowIndex);
        fireTableRowsDeleted(rowIndex, rowIndex);
    }
}
